package net.atomtree.corrsepond.spider;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;

import java.io.IOException;

/**
 * Created by czk on 2016/1/5.
 */
public class SpiderImpl implements  Spider{

    @Override
    public Document getHtml(SpiderContext context) throws Exception {
        String url=context.url;
        System.out.printf("url:"+url);
        if(null!=url) {
            Document doc = null;
            try {
                doc = Jsoup.connect(url).get();
                return doc;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        throw new Exception("url is null or error url");
    }

    @Override
    public Element getBody(SpiderContext context) throws Exception {
        return getHtml(context).body();
    }

    @Override
    public Elements getPassage(SpiderContext context) throws Exception {
        return null;
    }

}
